#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

const int step[4][2] = {
	{-1, 0}, {1, 0}, {0, -1}, {0, 1}
};
int n, m, k;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::freopen("grid.in", "r", stdin);
	std::freopen("grid.out", "w", stdout);

	std::cin >> n >> m >> k;
	std::vector<std::pair<int, int>> points(k);
	std::vector<int> a, b;
	a.reserve(3 * k), b.reserve(3 * k);
	for(auto& e : points) {
		std::cin >> e.first >> e.second;
		a.push_back(e.first);
		a.push_back(e.first - 1);
		a.push_back(e.first + 1);
		b.push_back(e.second);
		b.push_back(e.second - 1);
		b.push_back(e.second + 1);
	}
	sort(a.begin(), a.end()), a.erase(unique(a.begin(), a.end()), a.end());
	sort(b.begin(), b.end()), b.erase(unique(b.begin(), b.end()), b.end());
	for(auto& e : points) {
		e.first = lower_bound(a.begin(), a.end(), e.first) - a.begin();
		e.second = lower_bound(b.begin(), b.end(), e.second) - b.begin();
	}
	n = a.size();
	m = b.size();
	std::vector<std::vector<bool>> map(n, std::vector<bool>(m));
	int ans = 0;
	auto check = [&](int x, int y) -> bool {
		return 0 <= x && x < n && 0 <= y && y < m;
	};
	std::function<void(int, int)> dfs = [&](int x, int y) {
		if(map[x][y]) return;
		map[x][y] = 1, ++ans;
		for(int i = 0; i < 4; ++i) {
			int nx = x + step[i][0];
			int ny = y + step[i][1];
			if(check(nx, ny) && !map[nx][ny]) {
				int c = 0;
				for(int j = 0; j < 4; ++j) {
					int tx = nx + step[j][0];
					int ty = ny + step[j][1];
					if(check(tx, ty) && map[tx][ty]) ++c;
				}
				if(c >= 2) dfs(nx, ny);
			}
		}
	};
	for(auto e : points) dfs(e.first, e.second);
	std::cout << ans << "\n";
	return 0;
}
